package com.ranqianhuii.ojbackendserviceclient.service;

import com.ranqianhui.ojbackendcommon.common.ErrorCode;
import com.ranqianhui.ojbackendcommon.constant.UserConstant;
import com.ranqianhui.ojbackendcommon.exception.BusinessException;
import com.ranqianhui.ojbackendcommon.utils.JwtTool;
import com.ranqianhui.ojbackendmodel.model.entity.User;
import com.ranqianhui.ojbackendmodel.model.enums.UserRoleEnum;
import com.ranqianhui.ojbackendmodel.model.vo.UserVO;
import org.springframework.beans.BeanUtils;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.Collection;
import java.util.List;

/**
 * 用户服务
 */
@FeignClient(name = "oj-backend-user-service",path = "/api/user/inner")
public interface UserClient{
    /**
     * 根据用户id查询用户
     * @param userId
     * @return
     */
        @GetMapping("/get/id")
        User getById(@RequestParam("userId") long userId);

    /**
     * 根据 ids 查询用户列表
     * @param idList
     * @return
     */
    @GetMapping("/get/ids")
        List<User> listByIds(@RequestParam("idList") Collection<Long> idList);

    /**
     * 获取当前登录的用户
     * @param request
     * @return
     */
     User getLoginUser(HttpServletRequest request);

    /**
     * 获取脱敏后的用户信息
     * @param user
     * @return
     */
    default UserVO getUserVO(User user) {
        if (user == null) {
            return null;
        }
        UserVO userVO = new UserVO();
        BeanUtils.copyProperties(user, userVO);
        return userVO;
      }

    /**
     * 判断是否为管理员
     * @param user
     * @return
     */
    default boolean isAdmin(User user) {
        return user != null && UserRoleEnum.ADMIN.getValue().equals(user.getUserRole());
    }

    /**
     * 是否为管理员
     *
     * @param request
     * @return
     */

     boolean isAdmin(HttpServletRequest request) ;

}
